/*kZime*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <algorithm>
#define MAXN 2333
using namespace std;
inline int read() {
	int k = 0, f = 1; char c = getchar();
	for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
	return k * f;
}
/*-----------------------------------------------------------------------------*/

struct page{
	int l, r;
	bool flag;
}p[MAXN];

int n, m, ans;

void f_w(int l, int r, int k, int be){
	while(k <= m && (l > p[k].r || r < p[k].l)) k++;
	if(k > m) {
		p[be].flag = 1;
		return;
	}
	if(l<p[k].l) f_w(l, p[k].l - 1, k, be);
	if(r>p[k].r) f_w(p[k].r + 1, r, k, be);
}

int main() {
//#ifndef MYLAB
//	freopen("ha14d.in", "r", stdin);
//	freopen("ha14d.out", "w", stdout);
//#else
//	freopen("in.txt", "r", stdin);
//#endif

	n = read();
	m = read();
	for(int i = 1; i <= m; i++) {
		p[i].l= read();
		p[i].r = read();
	}

	for(int i = 1; i <= m; i++) {
		f_w(p[i].l, p[i].r, i + 1, i);
	}
	for(int i = 1; i <= m; i++) if(p[i].flag) ans++;

	printf("%d", ans);

	return 0;
}
